<?php

namespace cccmvc;

class Model
{
    protected string $table;
    protected array $attributes;
    protected ?Database $db = null;

    public function __construct()
    {
        $this->db = (Application::$app)->database;
    }

    /**
     * @return string
     */
    public function getTable(): string
    {
        return $this->table;
    }

    /**
     * @param string $table
     */
    public function setTable(string $table): void
    {
        $this->table = $table;
    }

    public function attributes(): array
    {
        return $this->attributes;
    }

    public function get(array $where)
    {
    }

    public function find($id)
    {
        $sql = "select * from " . $this->getTable() . " where id = ?";
        $query = $this->db->prepare($sql);
        $query->execute([$id]);
        $data = $query->fetch();

        return $data;
    }

    public function create($data)
    {

    }

    public function delete($id)
    {

    }

    public function update($data, $where)
    {

    }
}